<template>
	<div class="inter">
		<el-row>
		    <el-col :span="6">
				<el-button @click="vip" style="width: 100px;margin-left: -240px;">会员列表</el-button>
			</el-col>
			<el-col :span="6">
				<el-button @click="stored" style="width: 100px;margin-left: -740px;">储值管理</el-button>
			</el-col>
			<el-col :span="6">
				<el-button @click="inter" style="width: 100px;margin-left: -1237px;">积分管理</el-button>
		    </el-col>
		</el-row>
		
		<!-- ******************************模糊查询***************************** -->
		<el-form ref="form" :model="cxform" :inline="true">
			<el-form-item label="会员等级">
				<el-select v-model="cxform.vipgradeId" placeholder="请选择会员等级" clearable>
					<el-option v-for="g in indentstable" :label="g.name" :value="g.id"></el-option>
				</el-select>
			</el-form-item>
			
			<el-form-item label="">
				<el-input v-model="cxform.sname" placeholder="会员卡号/会员姓名/手机号" clearable></el-input>
			</el-form-item>
			
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="cx">搜索</el-button>
			</el-form-item>
			
			<el-button type="success" style="float: right;" icon="el-icon-download">导出</el-button>
			
		</el-form>

		<!-- **************************列表数据-************************* -->
		<el-table :data="tableData" style="width: 100%" :header-cell-style="{background:'#c2c5f6',color:'black'}">
			<el-table-column type="selection"></el-table-column>
			<el-table-column prop="id" label="序号">
			</el-table-column>
			<el-table-column prop="cardid" label="卡号">
			</el-table-column>
			<el-table-column label="会员等级" width="100">
				<template v-slot="scope">
					<b style="font-size: 16px;color: gold;">{{scope.row.vname}}</b>
				</template>
			</el-table-column>
			<el-table-column prop="sname" label="会员名称">
			</el-table-column>
			<el-table-column prop="phone" label="手机号">
			</el-table-column>
			<el-table-column prop="sumscore" label="积分">
			</el-table-column>
			<el-table-column prop="status" label="状态">
				<el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949">
				</el-switch>
				<!-- <template slot-scope="scope">
					<el-switch v-model="scope.row.isRecommendTwo" active-color="#00ff24" @change="handelUpdate(scope.$index, scope.row)"
					 inactive-color="#DCDFE6" :active-value="true" :inactive-value="false"></el-switch>
				</template> -->
			</el-table-column>
			<el-table-column label="操作" width="350px">
					<template v-slot="scope">
						<el-button type="infor">积分变动</el-button>
						<el-button type="infor" @click="openjiluDialog(scope.row)">积分变动记录</el-button>
					</template>
		
				</el-table-column>
		</el-table>
		<!-- ********************************分页查询******************************* -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current"
		 :page-sizes="sizes" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
		</el-pagination>
		
		
		<el-dialog :title="title+'记录'" :visible.sync="jiluDialogVisible" width="40%">
			<h4 align="left">会员卡:{{this.form.cardid}}</h4>
			<h4 align="left">会员姓名:{{this.form.sname}}</h4>
			<h4 align="left">积分余额:{{this.form.sumscore}}</h4>
			<el-table :data="tableData1" :header-cell-style="{background:'#c2c5f6',color:'black'}">
				<!-- <el-table-column type="selection"></el-table-column> -->
				<el-table-column prop="createtime" label="时间">
				</el-table-column>
				<el-table-column prop="type" label="变更操作">
				</el-table-column>
				<el-table-column prop="number" label="数量">
				</el-table-column>
				<el-table-column prop="uname" label="操作员">
				</el-table-column>
				<el-table-column prop="bz" label="备注">
				</el-table-column>
			</el-table>
			<!-- ********************************分页查询******************************* -->
			<el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :current-page="current1"
			 :page-sizes="sizes1" :page-size="size1" layout="total, sizes, prev, pager, next, jumper" :total="total1">
		
			</el-pagination>
			<el-form ref="form" :model="form" label-width="80px">
				<el-form-item >
					<el-button @click="jiluDialogVisible=false" >关闭</el-button>
				</el-form-item>
			</el-form>
		
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				indentstable: [],
				tableData: [],
				tableData1: [],
				list: [],
				total: 0,
				title:'',
				size: 5,
				sizes: [5, 10, 15],
				current: 1,
				size1: 3,
				total1: 0,
				sizes1: [3, 5, 8],
				current1: 1,
				dialogVisible: false,
				jiluDialogVisible: false,
				formData: {},
				form: {},
				cxform:{},
				value1: '',
				createtime: [],
				value: true,
				pickerOptions: {
					shortcuts: [{
						text: '最近一周',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
							picker.$emit('pick', [start, end]);
						}
					}, {
						text: '最近一个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
							picker.$emit('pick', [start, end]);
						}
					}, {
						text: '最近三个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
							picker.$emit('pick', [start, end]);
						}
					}]
				}

			}
		},
		created() {
			this.initDate();
			this.cunchuDate();
			this.initIndents();
		},
		methods: {
			handelUpdate(index, row) {
				// ：active-value得为true
				// ：inactive-value得为false
				let flag = row.isRecommendTwo //保存点击之后v-modeld的值(true，false)
			
				row.isRecommendTwo = !row.isRecommendTwo //保持switch点击前的状态
			
				this.$confirm('是否确认此操作?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					if (flag) {
						row.isRecommendTwo = true
						// 逻辑处理
						this.$message.success('打开成功!')
					} else {
						row.isRecommendTwo = false
						// 逻辑处理
						this.$message.success('关闭成功！')
					}
				}).catch(() => {
					this.$message.info('取消操作！')
				});
			},
			vip(){
				this.$router.push("/vip");
			
			},
			stored(){
				this.$router.push("/stored");
			},
			inter(){
				this.$router.push("/inter");
			},
			initIndents() {
				this.axios.get('http://localhost:8089/vipgrade/list').then((res) => {
					this.indentstable = res.data;
				})
			},
			openjiluDialog(row) {
				if (row) {
					this.title = '充值/退款';
					//数据回显
					this.form = row;
					//头像回显
					this.img = row.img;
				} else {
					this.form = {};
					this.title = '充值';
				}
				this.jiluDialogVisible = true;
			},
			handleSizeChange1(val) {
				console.log(`每页 ${val} 条`);
				this.size1 = val
				this.cunchuDate()
			},
			handleCurrentChange1(val) {
				console.log(`当前页: ${val}`);
				this.current1 = val
				this.cunchuDate()
			},
			cunchuDate() {
				this.axios.get('http://localhost:8089/score/list', {
					params: {
						size: this.size1,
						current: this.current1
			
					}
				}).then(res => {
					if (res) {
						this.tableData1 = res.data.obj.records
						this.total1 = res.data.obj.total
					}
				})
			},
			initDate() {
				this.axios.get('http://localhost:8089/vipperson/list', {
					params: {
						size: this.size,
						current: this.current,
						vname: this.cxform.vname,
						stime: this.cxform.createtime ? this.cxform.createtime[0] : '',
						etime: this.cxform.createtime ? this.cxform.createtime[1] : '',
						sname: this.cxform.sname,
						vipgradeId: this.cxform.vipgradeId

					}
				}).then(res => {
					if (res) {
						this.tableData = res.data.obj.records
						this.total = res.data.obj.total
					}
				})
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.size = val
				this.initDate()
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.current = val
				this.initDate()
			},
			cx() {
				this.current = 1
				this.initDate()
			}

		}
	}
</script>

<style>
</style>
